package com.cruise.system.userhandle.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cruise.system.userapi.dto.UpdateUserDataCountDTO;
import com.cruise.system.userapi.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 彭闯
 * @since 2021-01-13
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * add data count
     * @param updateUserDataCountDTO
     */
    @Update("<script> " +
            " update sys_user " +
            "<set> " +
            "<if test='updateUserDataCount.fansCount != null and updateUserDataCount.fansCount != 0 '>" +
            " fans_count = IFNULL(fans_count, 0) + #{updateUserDataCount.fansCount}" +
            "</if>" +
            "<if test='updateUserDataCount.concernCount != null and updateUserDataCount.concernCount != 0 '>" +
            " , concern_count = IFNULL(concern_count, 0) + #{updateUserDataCount.concernCount}" +
            "</if>" +
            "<if test='updateUserDataCount.likeCount != null and updateUserDataCount.likeCount != 0 '>" +
            " , like_count = IFNULL(like_count, 0) + #{updateUserDataCount.likeCount}" +
            "</if>" +
            "<if test='updateUserDataCount.postCount != null and updateUserDataCount.postCount != 0 '>" +
            " , post_count = IFNULL(post_count, 0) + #{updateUserDataCount.postCount}" +
            "</if>" +
            "</set>" +
            " where id = #{updateUserDataCount.id}" +
            "" +
            "</script>")
    void updateUserDataCountAdd(@Param("updateUserDataCount") UpdateUserDataCountDTO updateUserDataCountDTO);


    /**
     * minus data count
     * @param updateUserDataCountDTO
     */
    @Update("<script> " +
            " update sys_user " +
            "<set> " +
            "<if test='updateUserDataCount.fansCount != null and updateUserDataCount.fansCount != 0 '>" +
            " fans_count = IFNULL(fans_count, 0) - #{updateUserDataCount.fansCount}" +
            "</if>" +
            "<if test='updateUserDataCount.concernCount != null and updateUserDataCount.concernCount != 0 '>" +
            " ,  concern_count = IFNULL(concern_count, 0) - #{updateUserDataCount.concernCount}" +
            "</if>" +
            "<if test='updateUserDataCount.likeCount != null and updateUserDataCount.likeCount != 0 '>" +
            " , like_count = IFNULL(like_count, 0) - #{updateUserDataCount.likeCount}" +
            "</if>" +
            "<if test='updateUserDataCount.postCount != null and updateUserDataCount.postCount != 0 '>" +
            " , post_count = IFNULL(post_count, 0) - #{updateUserDataCount.postCount}" +
            "</if>" +
            "</set>" +
            " where id = #{updateUserDataCount.id}" +
            "" +
            "</script>")
    void updateUserDataCountMinus(@Param("updateUserDataCount") UpdateUserDataCountDTO updateUserDataCountDTO);
}
